#ifndef PRAXIS_UI_VARIABLE_MONITOR_CTRL_H_
#define PRAXIS_UI_VARIABLE_MONITOR_CTRL_H_

#include <windows.h>

#include <memory>

#include "praxis/core/backend_stubs.h"
#include "praxis/services/machine_simulator.h"  // Needed for observer registration

namespace praxis {
/**
 * @class VariableMonitorCtrl
 * @brief A UI control that displays real-time machine state variables.
 */
class PRAXIS_API VariableMonitorCtrl {
 public:
  VariableMonitorCtrl(HINSTANCE h_instance, HWND h_parent);
  ~VariableMonitorCtrl();

  VariableMonitorCtrl(const VariableMonitorCtrl&) = delete;
  VariableMonitorCtrl& operator=(const VariableMonitorCtrl&) = delete;

  /**
   * @brief Creates the UI controls for the monitor.
   */
  void Create(int x, int y, int width, int height, int control_id);

  /**
   * @brief Sets the data source for the monitor.
   *
   * This method populates the variable list from the schema and registers
   * itself as an observer to the simulator to receive live updates.
   * @param simulator The machine simulator instance.
   * @param schema The sub-schema for `machine_state_variables`.
   */
  void SetDataSource(MachineSimulator& simulator, const json& schema);

  /**
   * @brief Resizes the control and its children to fit new dimensions.
   * NEW: Handles window resizing.
   */
  void Resize(int x, int y, int width, int height);

 private:
  // The public interface does not expose update methods.
  // Updates are pushed from the simulator via the registered observer.
  void OnStateUpdated(const json& new_state);

  struct Impl;
  std::unique_ptr<Impl> impl_;
};
}  // namespace praxis

#endif  // PRAXIS_UI_VARIABLE_MONITOR_CTRL_H_
